package com.gzmu.face.mapper;

import com.gzmu.face.entity.Verifypush;
import com.baomidou.mybatisplus.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author xiaobo Yan
 * @since 2020-05-29
 */
@Mapper
public interface VerifypushMapper extends BaseMapper<Verifypush> {
    @Select("SELECT * FROM t_verifypush WHERE remark='0' ORDER BY createtime  LIMIT 1")
    Verifypush LoadData();

    @Select( "SELECT COUNT(id) FROM t_verifypush WHERE DATE(createtime) = curdate()" )
    Integer LoadDayTotal();

    @Select( "SELECT COUNT(id) FROM t_verifypush WHERE DATE(createtime) = curdate() AND TemperatureAlarm = 1" )
    Integer LoadAlarmTotal();

    @Update("UPDATE t_verifypush SET remark='1' WHERE remark='0' ORDER BY createtime  LIMIT 1")
    Integer UpdateData();

    @Select("<script>"+
            "SELECT v.Name,v.CreateTime,v.DeviceID,v.VerfyType,v.Temperature,v.TemperatureAlarm,v.SanpPic,f.idcardNum AS " +
            "PersonUUID FROM t_verifypush v,t_faceinfo f "+
            "WHERE v.PersonID=f.id "+
            "<when test='name != null'>"+
            "AND v.Name=#{name} "+
            "</when>"+
            "<when test='idcardNum != null'>"+
            "AND f.idcardNum=#{idcardNum} "+
            "</when>"+
            "<when test='stime != null'>"+
            "AND v.CreateTime BETWEEN #{stime} AND #{etime} "+
            "</when>"+
            "ORDER BY v.CreateTime desc limit #{start},#{limit}"+
            "</script>")
    List<Verifypush> selectVerify(Map<String,Object> params);
}
